Shader "TideShader/1_UV动画旋转"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Speed("旋转速度",float) = 1
    }
    SubShader
    {
        Tags
        {
            "Queue" = "Transparent"
        }
        Blend SrcAlpha OneMinusSrcAlpha
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float _Speed;

            float2 RotateZ(float2 pos, float angle)
            {
                float2 o;
                o.x = pos.x * cos(angle) - pos.y * sin(angle);
                o.y = pos.x * sin(angle) + pos.y * cos(angle);
                return o;
            }

            v2f vert(appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag(v2f i) : SV_Target
            {
                float angle = _Time.y * _Speed;

                float2 uv = i.uv - fixed2(0.5, 0.5);

                uv = RotateZ(uv, angle);

                fixed4 col = tex2D(_MainTex, uv + fixed2(0.5, 0.5));
                return col;
            }
            ENDCG
        }
    }
}